package com.keekus.common.web;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.filter.GenericFilterBean;

public class CommonFilter extends GenericFilterBean
{
  private String encoding = null;

  private String encodingParaName = "encoding";

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
    throws IOException, ServletException
  {
    request.setCharacterEncoding(this.encoding);
    response.setCharacterEncoding(this.encoding);
    filterChain.doFilter(request, response);
  }

  protected void initFilterBean() throws ServletException
  {
    this.encoding = getFilterConfig().getInitParameter(this.encodingParaName);
  }
}